// Problem: 
// Contest: 
// URL: 
// Memory Limit: 
// Time Limit: 
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
signed main()
{
	string s;
	bool f,f0=0;
	int l1=0,l2=0,r1=0,r2=0,count=0;
	int tl1=0,tl2=0,tr1=0,tr2=0;
	cin>>s>>f;
	int len=s.length();
	for(int i=0;i<len;i++)
	{
		if(s[i]=='(')f0=1,count++;
		if(s[i]==')')f0=0;
		if(s[i]=='L'&&(s[i+1]!='\''||i+1==len))
		{
			if(f0)l1++;
			else 
			{
				count++;
				l1++;
				if(l2>tl2)tl2=l2;
				l2=0;
				if(r1>tr1)tr1=r1;
				r1=0;
				if(r2>tr2)tr2=r2;
				r2=0;
			}
		}
		if(s[i]=='L'&&s[i+1]=='\'')
		{
			if(f0)l2++;
			else 
			{
				count++;
				l2++;
				if(l1>tl1)tl1=l1;
				l1=0;
				if(r1>tr1)tr1=r1;
				r1=0;
				if(r2>tr2)tr2=r2;
				r2=0;
			}
		}
		if(s[i]=='R'&&(s[i+1]!='\''||i+1==len))
		{
			if(f0)r1++;
			else 
			{
				count++;
				r1++;
				if(l2>tl2)tl2=l2;
				l2=0;
				if(l1>tl1)tl1=l1;
				l1=0;
				if(r2>tr2)tr2=r2;
				r2=0;
			}
		}
		if(s[i]=='R'&&s[i+1]=='\'')
		{
			if(f0)r2++;
			else 
			{
				count++;
				r2++;
				if(l2>tl2)tl2=l2;
				l2=0;
				if(r1>tr1)tr1=r1;
				r1=0;
				if(l1>tl1)tl1=l1;
				l1=0;
			}
		}
	}
	if(l1>tl1)tl1=l1;
	if(l2>tl2)tl2=l2;
	if(r1>tr1)tr1=r1;
	if(r2>tr2)tr2=r2;
	if(f)cout<<count<<endl<<tl1<<" "<<tl2<<" "<<tr1<<" "<<tr2;
	else cout<<count;
	return 0;
}
